#ifndef PRVP_INITIALSOLUTION_TEST_HPP_
#define PRVP_INITIALSOLUTION_TEST_HPP_

#include "../OptFrame/InitialSolution.h"
#include "../OptFrame/Util/TestSolution.hpp"

#include "ProblemInstance.hpp"

#include "Representation.h"
#include "Solution.h"

#include "Evaluator.hpp"

#include <list>

#include <algorithm>
#include <stdlib.h>

#define EXT1 4
#define EXT2 5

using namespace std;

class PRVPInitialSolutionTest: public InitialSolution<RepPRVP>
{
private:
	PRVPProblemInstance& pPRVP;
	RandGen& rg;

	SolutionPRVP& randomica()
	{
		RepPRVP rep;
		vector<vector<int> >* v = new vector<vector<int> > (3);
		vector<int> rota;

		//Scanner* sc = new Scanner("8 26 31 28 3 36 35 20 22 1 32 47 4 17 42 19 40 41 13 18");
		Scanner* sc = new Scanner("8 26 31 28 3 36 35 20 22 1 32 47 4 27 11 2 29 21 16 50 34");
		rota.clear();
		while (sc->hasNext())
			rota.push_back(sc->nextInt());

		random_shuffle(rota.begin(), rota.end());

		int i = 0;
		while (i < rota.size())
		{
			int pos = rand() % 3;
			v->at(pos).push_back(rota.at(i));
			i++;
		}

		rep.push_back(*v);

		v = new vector<vector<int> > (3);

		//sc = new Scanner("6 14 25 24 43 7 23 48 27 11 2 29 21 16 50 34 30 9 38 46 5 49 10 39 33 45 15 44 37 12");
		sc = new Scanner("6 14 25 24 43 7 23 48 17 42 19 40 41 13 18 30 9 38 46 5 49 10 39 33 45 15 44 37 12");
		rota.clear();
		while (sc->hasNext())
			rota.push_back(sc->nextInt());

		random_shuffle(rota.begin(), rota.end());

		i = 0;
		while (i < rota.size())
		{
			int pos = rand() % 3;
			v->at(pos).push_back(rota.at(i));
			i++;
		}

		rep.push_back(*v);
		//delete v;

		delete v;

		return *new TestSolution<RepPRVP> (rep);
	}

	SolutionPRVP& best()
	{
		RepPRVP rep;
		vector<vector<int> >* v = new vector<vector<int> > (3);
		vector<int> rota;

		Scanner* sc = new Scanner("8 26 31 28 3 36 35 20 22 1 32");
		rota.clear();
		while (sc->hasNext())
			rota.push_back(sc->nextInt());


		v->at(0) = rota;

		sc = new Scanner("47 4 17 19 40 41 13");
		rota.clear();
		while (sc->hasNext())
			rota.push_back(sc->nextInt());

		v->at(1) = rota;

		/*rota.clear();
		rota.push_back(46);
		v->at(2) = rota;*/

		rep.push_back(*v);

		v = new vector<vector<int> > (3);

		sc = new Scanner("6 14 25 24 43 7 23 48 27");
		rota.clear();
		while (sc->hasNext())
			rota.push_back(sc->nextInt());

		v->at(0) = rota;

		sc = new Scanner("11 2 29 21 16 50 34 30 9 38");
		rota.clear();
		while (sc->hasNext())
			rota.push_back(sc->nextInt());

		v->at(1) = rota;

		sc = new Scanner("5 49 10 39 33 45 15 44 37 12 46");
		rota.clear();
		while (sc->hasNext())
			rota.push_back(sc->nextInt());

		v->at(2) = rota;

		rep.push_back(*v);

		delete v;

		return *new TestSolution<RepPRVP> (rep);

	}

public:

	PRVPInitialSolutionTest(PRVPProblemInstance& _pPRVP, RandGen& _rg) : // If necessary, add more parameters
		pPRVP(_pPRVP), rg(_rg)
	{
	}

	~PRVPInitialSolutionTest()
	{}

	SolutionPRVP& generateSolution()
	{
		return randomica();
	}

};

#endif /*PRVP_INITIALSOLUTION_TEST_HPP_*/
